/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.util.ByteUtil;
/*     */ import com.zimbra.common.util.DevNullOutputStream;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.Message;
/*     */ import com.zimbra.cs.redolog.RedoPlayer;
/*     */ import com.zimbra.cs.redolog.util.RedoLogVerify;
/*     */ import com.zimbra.cs.store.MailboxBlob;
/*     */ import com.zimbra.cs.store.StoreManager;
/*     */ import java.io.File;
/*     */ import java.io.PrintStream;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestRedoLog
/*     */   extends TestCase
/*     */ {
/*     */   private static final String USER_NAME = "user1";
/*     */   private static final String RESTORED_NAME = "testredolog";
/*  47 */   private static final String NAME_PREFIX = TestRedoLog.class.getSimpleName();
/*     */   
/*     */   public void setUp() throws Exception
/*     */   {
/*  51 */     cleanUp();
/*     */   }
/*     */   
/*     */   public void testRedoLogVerify() throws Exception
/*     */   {
/*  56 */     RedoLogVerify verify = new RedoLogVerify(null, new PrintStream(new DevNullOutputStream()));
/*  57 */     assertTrue(verify.verifyFile(getRedoLogFile()));
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void testTestRestoreMessageToNewAccount()
/*     */     throws Exception
/*     */   {
/*  68 */     long startTime = System.currentTimeMillis();
/*  69 */     Mailbox sourceMbox = TestUtil.getMailbox("user1");
/*  70 */     Message sourceMsg = TestUtil.addMessage(sourceMbox, NAME_PREFIX + " testRestoreMessageToNewAccount");
/*  71 */     String sourceContent = new String(sourceMsg.getContent());
/*  72 */     assertTrue(sourceContent.length() != 0);
/*     */     
/*     */ 
/*  75 */     Account destAccount = TestUtil.createAccount("testredolog");
/*  76 */     RedoPlayer player = new RedoPlayer(false, true, false, false, false);
/*  77 */     Map<Integer, Integer> idMap = new HashMap();
/*  78 */     Mailbox destMbox = MailboxManager.getInstance().getMailboxByAccount(destAccount);
/*  79 */     idMap.put(Integer.valueOf(sourceMbox.getId()), Integer.valueOf(destMbox.getId()));
/*  80 */     player.scanLog(getRedoLogFile(), true, idMap, startTime, Long.MAX_VALUE);
/*     */     
/*     */ 
/*  83 */     List<Integer> destIds = TestUtil.search(destMbox, "in:inbox " + NAME_PREFIX, MailItem.Type.MESSAGE);
/*  84 */     assertEquals(1, destIds.size());
/*  85 */     Message destMsg = destMbox.getMessageById(null, ((Integer)destIds.get(0)).intValue());
/*  86 */     String destContent = new String(destMsg.getContent());
/*  87 */     assertEquals(sourceContent, destContent);
/*     */     
/*     */ 
/*  90 */     MailboxBlob blob = sourceMsg.getBlob();
/*  91 */     assertNotNull(blob);
/*  92 */     sourceContent = new String(ByteUtil.getContent(StoreManager.getInstance().getContent(blob), sourceContent.length()));
/*  93 */     assertEquals(destContent, sourceContent);
/*     */   }
/*     */   
/*     */   private File getRedoLogFile() {
/*  97 */     return new File("/opt/zimbra/redolog/redo.log");
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/* 102 */     cleanUp();
/*     */   }
/*     */   
/*     */   private void cleanUp() throws Exception
/*     */   {
/* 107 */     TestUtil.deleteTestData("user1", NAME_PREFIX);
/* 108 */     TestUtil.deleteAccount("testredolog");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestRedoLog.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */